<?php
/*
 * Created on Feb 23, 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
	include('includes/session.php');
	$title = TT_SEARCH;	
	include('header.inc');
	include('lefter.inc');	
	echo '<script type="text/javascript" src="js/previewpopup.js"></script>';
	
	echo '<link href="css/popup/default.css" type="text/css" rel="stylesheet">'; 
	echo '<link href="css/popup/alphacube.css" type="text/css" rel="stylesheet">';
	if(count($searchArray) > 0){
		$start=$searchArray['start'];
		if(strlen($start) > 0 and !is_numeric($start)){
			echo "Data Error";
			exit;
		}
		$eu = ($start - 0);
		$limit = MAX_RECORD_SEARCH;
		$this1 = $eu + $limit;
		$back = $eu - $limit;
		$next = $eu + $limit;
		$num = 0;
		$stringGet = '';
		foreach($searchArray as $key => $value){
			if(!empty($value) && $key != 'start')
				$stringGet .= '&'.$key.'='.$value;
		}		
		$resultSearch = $reesNewModel->search($searchArray, $num, $eu, $limit);
		echo '<div id="col3">';
			echo '<div id="col3_content" class="clearfix"><a id="content" name="content"></a>';
				echo '<div class="subcolumns_oldgecko widget_space">';
					echo '<div class="widget_margins">';						
						echo '<div class="li_background li_height_big">';
						echo '<div id="li_experts" class="li_content">';
						echo '<h2>Kết quả tìm kiếm:</h2>';
						echo '<div class="clear"></div>';
						echo '<div class="floatbox">';
							echo '<div id="topExperts">';
								echo '<ul class="li_elements search">';
									while ($myrow = $reesNewModel->getArrayNameRees($resultSearch)) {
										echo '<li class="li_experts vcard" id="id65633">';
										echo '<h3 class="fn url"><a href="itemrestatedetail.php?itemid='.$myrow['id'].'&type=transaction&transactionId='.$myrow['rees_transaction_id'].'" class="org url person">&nbsp;&nbsp;'. $myrow['title'] .'</a></h3>';
										$imgPath = PATH_CONTENT_IMAGE.$myrow['image'];
										if(isset($myrow['image']) && !empty($myrow['image']) && file_exists($imgPath)){
											echo '<a href="#" title=""><img id="house'. $myrow['id'] .'" src="'. $imgPath .'" class="photosearch" alt=""/></a>';														
										}else{
											echo '<a href="#" title=""><img id="house'. $myrow['id'] .'" src="img/NoPhotoAvailable.jpg" class="photosearch" alt=""/></a>';
										}
										echo '<script type="text/javascript">';
											echo 'Event.observe( window, \'load\', function() {';
												echo 'repositionPreviewFor($( \'house'. $myrow['id'] .'\' ));';
												echo '$( \'house'. $myrow['id'] .'\' ).observe( \'mouseover\', showPreview );';
												echo '$( \'house'. $myrow['id'] .'\' ).observe( \'mouseout\', hidePreview );';
											echo '});';
										echo '</script>';
											
										echo '<p class="li_experts_content">';
											echo '<span class="tags"><strong>Mô tả: </strong>'. $myrow['description'] .'</span><br/>';
											echo '<span class="tags"><strong>Liên hệ: </strong>'. $myrow['contact'] .' - <strong>Lượt xem: </strong>'. $myrow['showNo'] .'<br/></span><br/>';											
										echo '</p>';
										echo '<div class="li_experts_tb">';
											echo '<div class="icon-li-publications" title="Publications" >Lượt xem: '. $myrow['showNo'] . ' - <img src="images/calendar-icon.png" />&nbsp;Ngày đăng tin: '. ConvertSQLDate($myrow['updateDate']) .' - Ngày hết hạn: '. ConvertSQLDate($myrow['endDate']) .'</div>';															
										echo '</div>';
										echo '</li>';	
									}									
								echo '</ul>';
								$reesNewModel->dataSeekResult($resultSearch, 0);
								while ($myrow = $reesNewModel->getArrayNameItem($resultSearch)){	
									$imgPath = PATH_ITEM_IMAGE.$myrow['image'];
									echo '<div id="house'. $myrow['id'] .'_preview" style="display: none" class="preview">';
										echo '<h3>'. $myrow['title'] .'</h3>';
										$widthheight = '';
										if (isset($myrow['image']) && !empty($myrow['image']) && file_exists($imgPath)){
											$imgPath = PATH_ITEM_IMAGE.$myrow['image'];
										}
										else {
											$imgPath = "img/NoPhotoAvailable.jpg";
											$widthheight = ' width="250" height="270"';
										}
										echo '<img src="'. $imgPath .'" alt="'. $myrow['title'] . '" '. $widthheight .'/>';										
									echo '</div>';
								}
								if($num > $limit ){
									echo '<div id="pager"><span style="font-size: 12px; face=Verdana">Trang </span>';
									if($back >=0) {  
										echo '<a href="'.$_SERVER['PHP_SELF'].'?start='.$back.$stringGet.'"><img src="img/icons/arrow_left.gif" width="16" height="16" /></a>';
									};
									$i=0;
									$l=1;
									for($i=0;$i < $num;$i=$i+$limit){
										if($i <> $eu){
											echo " <a href='".$_SERVER['PHP_SELF']."?start=$i".$stringGet."'><span style='font-size: 12px; face=Verdana'>$l</span></a> ";
										}
										else { 											
											echo '<span style="font-size: 18px; color: red; face=Verdana">'.$l.'</span>';													
										}
											$l=$l+1;
									}
									if($this1 < $num) {
										echo '<a href="'.$_SERVER['PHP_SELF'].'?start='.$next.$stringGet.'"><img src="img/icons/arrow_right.gif" width="16" height="16" /></a>';
									};
									echo '<span style="font-size: 12px; face=Verdana"> Tổng cộng '. $num .' bất động sản</span>';
									echo '</div>';
								}else{
									echo '<div id="pager">';
									echo '<span style="font-size: 12px; face=Verdana"> Tổng cộng '. $num .' bất động sản</span>';
									echo '</div>';
								}
							echo '</div>';
						echo '</div>';
						echo '</div>';
						echo '</div>';
						echo '</div>';
					echo '</div>';
				echo '</div>';
			echo '</div>';
		echo '</div>';
	}
	echo '<div id="col1" style="margin-left:20px;">';
	    echo '<div id="col1_content" class="clearfix" style="float:left;">';
		echo '<br/>';
			$cities = $cityModel->getCities();
			echo "<form id='frm_search' method='post' action='controllers/reesitem_controller.php'>";
			echo '<div class="subcolumns_oldgecko widget_space" style="width:100%">';
			echo '<div id="registration" class="widget_blue_background" >';
				echo '<h1 class="widget_header"><span class="icon-tab">TÌM BẤT ĐỘNG SẢN</span></h1>';							
				echo '<div class="widget_margins" style="background-color:transparent">';						
					echo '<fieldset style="width:40.6em; padding-left:3em; margin-left:8px; margin-right:8px;">';
					echo '<legend>Thông tin</legend>';
					echo '<div class="formFloatBox clearfix">';
						echo '<div class="required">';
							echo '<label for="title">Tiêu đề:</label>';
							echo '<input type="text" class="inputTextMedium" name="title" value="'.$searchArray['title'].'" />';
						echo '</div>';
						echo '<div class="required">';
							echo '<label for="address">Địa chỉ:</label>';
							echo '<input type="text" class="inputTextMedium" name="address" value="'.$searchArray['address'].'"/>';
						echo '</div>';
					echo '</div>';
					echo '<div class="formFloatBox clearfix">';
						echo '<div class="required">';
							echo '<label for="description">Mô tả:</label>';
							echo '<input type="text" class="inputTextMedium" name="description" value="'.$searchArray['description'].'"/>';
						echo '</div>';
						echo '<div class="required">';
							echo '<label for="direction">Hướng nhà:</label>';
							echo '<input type="text" class="inputTextMedium" name="direction" value="'.$searchArray['direction'].'"/>';
						echo '</div>';
					echo '</div>';
					echo '<div class="formFloatBox clearfix">';
						echo '<div class="required">';
							echo '<label for="reestype">Loại tin:*</label>';							
							echo '<select name="reestype" class="selectOneMedium">';
								echo '<option value="0">- Tất cả -</option>';
								while ($myrow = $transactionModel->getArrayNameTrans($trans)) {
									if($searchArray['reestype'] == $myrow['id'])
										echo '<option selected="selected" value="'. $myrow['id'] .'">'. $myrow['name'] .'</option>';
									else
										echo '<option value="'. $myrow['id'] .'">'. $myrow['name'] .'</option>';
								}
							echo '</select>';
							
						echo '</div>';
						echo '<div class="required">';
							echo '<label for="typehouse">Loại nhà:*</label>';
							echo '<select name="typehouse" class="selectOneMedium">';
								echo '<option value="0">- Tất cả -</option>';
								while ($myrow = $realestateModel->getArrayNameTypes($typehouse)) {
									if($searchArray['typehouse'] == $myrow['id'])
										echo '<option selected="selected" value="'. $myrow['id'] .'">'. $myrow['name'] .'</option>';
									else 
										echo '<option value="'. $myrow['id'] .'">'. $myrow['name'] .'</option>';
								}
							echo '</select>';
						echo '</div>';
					echo '</div>';
					echo '<div class="formFloatBox clearfix">';
						echo '<div class="required">';
							echo '<label for="region">Khu đô thị:</label>';
							echo '<select name="region" class="selectOneMedium">';
								echo '<option value="0">- Tất cả -</option>';
								while ($myrow = $cityModel->getArrayNameRegions($region)) {
									if($searchArray['region'] == $myrow['id'])
										echo '<option selected="selected" value="'. $myrow['id'] .'">'. $myrow['name'] .'</option>';
									else 
										echo '<option value="'. $myrow['id'] .'">'. $myrow['name'] .'</option>';
								}
							echo '</select>';
						echo '</div>';						
						echo '<div class="required">';
							echo '<label for="city">Tỉnh/TP:*</label>';
							echo '<select name="city" class="selectOneMedium" onchange="cityChange(this.value)">';
								echo '<option value="0">- Tất cả -</option>';
								while ($myrow = $cityModel->getArrayNameRegions($cities)) {
									if($searchArray['city'] == $myrow['id'])
										echo '<option selected="selected" value="'. $myrow['id'] .'">'. $myrow['name'] .'</option>';
									else 
										echo '<option value="'. $myrow['id'] .'">'. $myrow['name'] .'</option>';
								}
							echo '</select>';
						echo '</div>';
					echo '</div>';
					echo '<div class="formFloatBox clearfix">';
						echo '<div class="required">';														
						echo '</div>';
						echo '<div class="required">';
							echo '<label for="district">Quận/Huyện :</label>';
							echo '<select name="district" id ="district" class="selectOneMedium">';
								echo '<option value="0">- Chọn Tỉnh/TP -</option>';
							echo '</select>';
						echo '</div>';
					echo '</div>';
					echo '<div class="formFloatBox clearfix">';						
						echo '<div class="required">';
							echo '<label for="price">Mức giá bán/thuê (triệu/VNĐ): </label>';
							echo '<input type="text" class="inputTextMedium" name="price" value="'.$searchArray['price'].'"/>';
						echo '</div>';
						echo '<div class="required">';
							echo '<label for="size">Diện tích (m2): </label>';
							echo '<input type="text" class="inputTextMedium" name="size" value="'.$searchArray['size'].'"/>';
						echo '</div>';
					echo '</div>';
					echo '</fieldset>';	
					echo '<table><tr><td>';
						echo '<input type="submit" name="search" value="Tìm" class="button_orange_medium"/>';
					echo '</td><td>';
						echo '<input type="reset" value="Nhập lại" class="button_orange_medium"/>';
					echo '</td></tr></table>';
				echo '</div>';
			echo '</div>';
			echo '<input type="hidden" name="itemsearch" value="1" />';
			echo '</form>';
		echo '</div>';
		echo '</div>';
	echo '</div>';
	echo '<div id="col3">';
		echo '<div id="col3_content" class="clearfix"><a id="content" name="content"></a>';
	        echo '<div class="subcolumns_oldgecko widget_space">';
			// begin last new
			include('_lastnew.php');
			// end last new	
			echo '</div>';
		echo '</div>';
	echo '</div>';
	include('footer.inc');
?>
<script>
	function cityChange(value){
		var url = 'getDistrict.php?cityId=';
		new Ajax.Request(url + value,
		  {
		    method:'get',
		    onSuccess: function(transport){
				var cbxDistrict = document.getElementById('district');
				cbxDistrict.options.length = 0;
				cbxDistrict.options[0] = new Option('- Tất cả -', 0);
				var response = transport.responseText;
				var districts = eval( "(" + response + ")");
				for(i =0 ; i < districts.length; i ++)					
					cbxDistrict.options[cbxDistrict.options.length] = new Option(districts[i]['name'], districts[i]['id']);
		    },
		    onFailure: function(){ alert('Something went wrong...') }
		  });
	}
</script>